Machine Learning linear regression prediction

by: helix05, 8 years ago


Hello.
I try to predict from previously trained LinearRegression classifier, but I keep getting same error: shapes (15,5) and (9,) not aligned: 5 (dim 1) != 9 (dim 0).
Would you explain, please, what am I doing wrong?

[try:
    df=pd.read_csv('Stock.csv',names=['Date','High','Low','Close','Open','Volume'])
    df['Date']=pd.to_datetime(df['Date'],unit='s')
    df.set_index('Date',inplace=True)
      
    pickle_in=open('linearreg.pickle','rb')
    clf=pickle.load(pickle_in)


    forecast_set=clf.predict(np.array(df))
    df['Forecast']=np.nan

    last_date=df.iloc[-1].name
    last_unix=last_date.timestamp()
    five_minutes=300
    next_unix=last_unix+five_minutes

    for i in forecast_set:
        next_date=datetime.datetime.fromtimestamp(next_unix)
        next_unix+=300
        df.loc[next_date]=[np.nan for _ in range(len(df.columns)-1)]+[i]

    df['Close'].plot()
    df['Forecast'].plot()
    plt.legend(loc=4)
    plt.xlabel('Date')
    plt.ylabel('Price')
    plt.show()]
Thank you very much and Happy new year!!!




You must be logged in to post. Please login or register an account.



By looking at this code, it looks fine, but I am not privy to what your classifier is expecting.

From the looks of the error, the classifier is expecting a different shape of data than what you're feeding it.

Print out a sample x data's shape df.values[0].shape
...and then go back to whatever you used to train that classifier, and print out the .shape of one of your training featuresets, they are almost certainly not going to match.

You're probably not reading in your dataframe the same, or specifying which columns are of the featuresets...etc.

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.